<!--  -->
<template>
  <a-modal
    :maskClosable="false"
    :destroyOnClose="true"
    :title="title"
    centered
    :width="500"
    v-model="visible"
    @ok="handleOk"
  >
    <div class="content">
      <template v-if="proTypeList.length">
        <div v-for="item in proTypeList" :key="item.id">
          <a-checkbox-group v-model="typeIds">
            <a-row v-for="item in proTypeList" :key="item.id">
              <a-col :span="12">
                <a-checkbox :value="item.type">{{ item.name }}</a-checkbox>
              </a-col>
            </a-row>
          </a-checkbox-group>
        </div>
      </template>
      <template v-else> 暂无数据 </template>
    </div>
  </a-modal>
</template>

<script>
import { ProType, cooperationTypeMap } from '@/api/business/cooperation'
import Item from './item.vue'
export default {
  components: {
    Item,
  },
  data() {
    return {
      visible: false,
      title: '添加接入资源',
      proTypeList: [],
      typeIds: [],
      cooperationType: 1,
      cooperationTypeMap,
    }
  },
  computed: {},
  watch: {},
  methods: {
    show(cooperationType, tenantId) {
      this.cooperationType = cooperationType
      this.title = `添加${this.cooperationTypeMap[cooperationType]}资源`
      this.typeIds = []
      this.getProType({
        cooperationType,
        tenantId,
      })
      this.visible = true
    },
    async getProType(params) {
      let res = await ProType(params)
      this.proTypeList = res.data || []
    },
    handleOk() {
      if (!this.typeIds.length)
        return this.$message.error(`请选择${this.cooperationTypeMap[this.cooperationType]}的资源`)
      this.$emit('ok', this.typeIds)
      this.visible = false
    },
  },
  created() {},
  mounted() {},
}
</script>
<style lang="less" scoped>
.content {
  ::v-deep {
    .ant-checkbox-group {
      width: 100%;
    }
  }
}
</style>